home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 026a / diskscan.zip / DISKSCAN.C next >
C/C++ Source or Header  |  1990-12-12  |  3KB  |  151 lines

  1. /************************************************************************/
  2. /*
  3. ** DISKSCAN.C - Scan all directories on a drive, and list them on the
  4. **              screen.
  5. **
  6. **   usage:     DISKSCAN x:           (x is the drive letter)
  7. **
  8. **   To redirect the output to a text file:
  9. **
  10. **              DISKSCAN x: > filename.txt
  11. **
  12. **
  13. **  Brain Child Systems    This program I release to the public domain,
  14. **  P.O. Box 3882          ....but send me a dollar and make me holler!
  15. **  Austin, TX 78764
  16. **
  17. */
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <dir.h>
  22. #include <dos.h>
  23.  
  24. #define TRUE   1
  25. #define FALSE  0
  26.  
  27. void
  28. AppendMask(char *pacFullPath, char *pacPathSegment);
  29.  
  30. void
  31. ClimbTree(char *pacFullPath, char *pacPathSegment,
  32.           int *pfFoundDir);
  33.  
  34. void
  35. RemoveDir(char *pacFullPath, int iHowMany);
  36.  
  37. void
  38. RemoveMask(char *pacFullPath);
  39.  
  40. static char acDrive[] = "  \0";
  41. static char acBackSlash[] = "\\*.\0";
  42.  
  43. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  44. *
  45. *   AppendMask - Append the path segment onto the full
  46. *     path name.
  47. *
  48. */
  49. void
  50. AppendMask(char *pacFullPath, char *pacPathSegment) {
  51.  
  52.   if(!*pacPathSegment) {
  53.     strcat(pacFullPath, acDrive);
  54.     strcat(pacFullPath, acBackSlash);
  55.     return;
  56.   }
  57.   strcat(pacFullPath, pacPathSegment);
  58.   printf("%s\n", pacFullPath);
  59.   strcat(pacFullPath, acBackSlash);
  60.  
  61. }
  62. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  63.  
  64. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  65. *
  66. *   FUNCTION: ClimbTree
  67. *
  68. *
  69. */
  70. void
  71. ClimbTree(char *pacFullPath, char *pacPathSegment, int *pfFoundDir) {
  72.  
  73.   struct ffblk abFileBlock;
  74.   int fDirFound = FALSE;
  75.  
  76.   RemoveMask(pacFullPath);
  77.   AppendMask(pacFullPath, pacPathSegment);
  78.   *pfFoundDir = FALSE;
  79.   if(!findfirst(pacFullPath, &abFileBlock, FA_DIREC))
  80.     do {
  81.       if(strncmp(abFileBlock.ff_name, ".", 1) &&
  82.          abFileBlock.ff_attrib == FA_DIREC) {
  83.         *pfFoundDir = TRUE;
  84.         ClimbTree(pacFullPath, abFileBlock.ff_name,
  85.                                &fDirFound);
  86.       }
  87.     } while(!findnext(&abFileBlock));
  88.  
  89.   if(!fDirFound)
  90.     RemoveDir(pacFullPath, 2);
  91.  
  92. }
  93. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  94.  
  95. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  96. *
  97. *   RemoveDir -
  98. *
  99. */
  100. void
  101. RemoveDir(char *pacFullPath, int iHowMany) {
  102.  
  103.   while(*pacFullPath++);
  104.   while(iHowMany--) {
  105.     while(*pacFullPath != '\\')
  106.         *pacFullPath-- = 0;
  107.  
  108.     if(iHowMany)
  109.       *pacFullPath = 0;
  110.   }
  111.  
  112. }
  113. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  114.  
  115. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
  116. *
  117. *   RemoveMask -
  118. *
  119. */
  120. void
  121. RemoveMask(char *pacFullPath) {
  122.  
  123.   while(*pacFullPath++);
  124.   while(*pacFullPath != '\\')
  125.       *pacFullPath-- = 0;
  126.  
  127. }
  128. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  129.  
  130.  
  131. main(int argc, char *argv[]) {
  132.  
  133.   char cBackSlash[] = "\\";
  134.   char acFullPath[100];
  135.   char acPathSegment[13];
  136.   int fDummy;
  137.  
  138.   if(argc < 2) {
  139.     cprintf("which drive?");
  140.     return;
  141.   }
  142.   else memcpy(acDrive, argv[1], 2);
  143.  
  144.   fDummy = TRUE;
  145.   memset(&acFullPath, NULL, 100);
  146.   memset(&acPathSegment, NULL, 13);
  147.   ClimbTree(acFullPath, "", &fDummy);
  148.  
  149. }
  150.  
  151.